<!-- 地图 -->
<template>
  <div class="goods-map-wrap">
    <iframe id="bi_iframe"
            ref="frame"
            frameborder="0"
            scrolling="auto"
            name="myFrame"
            style="height: 100vh;"
            :src="iframeUrl"
            @load="adjustIframe"></iframe>
  </div>
</template>

<script>
// import eventBus from "@/libs/eventBus";
import platformConfig from "@/config/platformConfig";

export default {
  name: "GoodsMap",
  props: {
    mapType: {
      type: Number,
      default: 1
    },
    orderId: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
      routeParams: JSON.parse(sessionStorage.getItem('ROUTEER_OPEN_PARAMS')),
      params: {
        token: sessionStorage.getItem("token"),
        orderId: "",
        type: null // 1 订单 2 运单
      }
    };
  },
  computed: {
    iframeUrl () {
      return platformConfig.trajectory[process.env.NODE_ENV] || "";
    }
  },
  created () {
    this.params.type = this.$route.query.mapType
    this.params.orderId = this.$route.query.orderId || this.$route.query.waybillId
  },
  // computed: {
  //   routerOpenParams () {
  //     return JSON.parse(sessionStorage.getItem('ROUTEER_OPEN_PARAMS'))
  //   }
  // },
  mounted () {
    // iframe 自适应
    // this.iframeUrl = process.env.NODE_ENV === 'production' ? 'https://ntrajectory.wlyuan.com.cn/s/' : "http://dev.com/dome/index.html";
    // this.iframeUrl = `https://ntrajectory.wlyuan.com.cn/s/`;
    // this.iframeUrl = `http://192.168.1.168/`
    this.initFrame(this.iframeUrl);
    // eventBus.$off("rowClickCross");
    // eventBus.$on("rowClickCross", (event) => {
    //   this.params.orderId = event.orderId;
    //   let iframeWin = this.$refs["frame"].contentWindow;
    //   iframeWin.postMessage(this.params, this.iframeUrl);
    // });
  },
  methods: {
    initFrame (url) {
      let _this = this
      let Frame = _this.$refs["frame"];
      if (Frame.attachEvent) {
        // 兼容浏览器判断
        Frame.attachEvent("onload", function () {
          let iframeWin = Frame.contentWindow;
          iframeWin.postMessage(_this.params, url);
        });
      } else {
        Frame.onload = function () {
          let iframeWin = Frame.contentWindow;
          iframeWin.postMessage(_this.params, url);
        };
      }
    },
    adjustIframe () {
      var ifm = document.getElementById("bi_iframe");
      ifm.height = document.documentElement.clientHeight - 58;
      ifm.width = document.documentElement.clientWidth;
    }
  }
};
</script>

<style>
</style>
